<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Robomaster | 面试博客</title><meta name="author" content="Luo Jiehao"><meta name="copyright" content="Luo Jiehao"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="2018年RoboMaster机甲大师赛比赛经历">
<meta property="og:type" content="article">
<meta property="og:title" content="Robomaster">
<meta property="og:url" content="https://luo_13.gitee.io/interview/2021/03/07/RoboMaster/index.html">
<meta property="og:site_name" content="面试博客">
<meta property="og:description" content="2018年RoboMaster机甲大师赛比赛经历">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg">
<meta property="article:published_time" content="2021-03-07T12:48:40.000Z">
<meta property="article:modified_time" content="2021-03-07T14:13:32.524Z">
<meta property="article:author" content="Luo Jiehao">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg"><link rel="shortcut icon" href="/interview/img/favicon.png"><link rel="canonical" href="https://luo_13.gitee.io/interview/2021/03/07/RoboMaster/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/interview/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/interview/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-03-07 22:13:32'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/interview/null" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/interview/archives/"><div class="headline">Articles</div><div class="length-num">4</div></a></div></div></div><hr/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/interview/">面试博客</a></span><div id="menus"><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Robomaster</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2021-03-07T12:48:40.000Z" title="Created 2021-03-07 20:48:40">2021-03-07</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2021-03-07T14:13:32.524Z" title="Updated 2021-03-07 22:13:32">2021-03-07</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="背景介绍"><a href="#背景介绍" class="headerlink" title="背景介绍"></a>背景介绍</h3><p>RoboMaster是一个全国大学生机器人竞赛，是一个以射击为主的机器人竞赛  </p>
<p>团队在规则允许的范围内自主研制机器人<br><img src="/interview/2021/03/07/RoboMaster/%E6%9C%BA%E5%99%A8%E4%BA%BA%E7%A7%8D%E7%B1%BB.jpg" alt="机器人种类"><br>每种机器人都有一定的血量，如果血量归零，机器人被淘汰。   </p>
<p>比赛过程中英雄机器人、步兵机器人、空中机器人、工程机器人由团队成员控制，哨兵机器人为自动机器人。英雄机器人、步兵机器人、空中机器人、哨兵机器人可发生弹丸，若弹丸击中对方机器人身上安装的装甲片，被击中的机器人就会被扣除一定量的血量，若某方机器人全部被淘汰或者某方的基地机器人被淘汰，则输掉比赛。所以比赛的其中一个重点是如何更快更精准得打击对方机器人。<br><img src="/interview/2021/03/07/RoboMaster/%E6%AF%94%E8%B5%9B%E7%A4%BA%E6%84%8F%E5%9B%BE.jpg" alt="比赛示意图">   </p>
<h3 id="主要贡献"><a href="#主要贡献" class="headerlink" title="主要贡献"></a>主要贡献</h3><p>1、负责开发维护各类机器人的自动射击模块</p>
<h3 id="自动射击模块功能"><a href="#自动射击模块功能" class="headerlink" title="自动射击模块功能"></a>自动射击模块功能</h3><p>自动射击模块主要分为三个部分  </p>
<ol>
<li>寻找装甲片位置</li>
<li>估算装甲片距离</li>
<li>调整射击角度和速度  </li>
</ol>
<p><img src="/interview/2021/03/07/RoboMaster/%E6%B5%81%E7%A8%8B.jpg" alt="流程">  </p>
<h3 id="功能实现"><a href="#功能实现" class="headerlink" title="功能实现"></a>功能实现</h3><ul>
<li>寻找装甲片位置  </li>
</ul>
<p>寻找装甲片位置的目的是寻找自动打击的目标。如上图所示，装甲片是一个矩形金属板块，装有压力传感器以及发光灯条和贴有号码牌，压力传感器用来感应是否受到打击，发光灯条和号码牌为装甲片标志物。  </p>
<p>在实现过程中，主要关注的是更为明显的发光灯条标志物。  </p>
<p>算法流程：</p>
<ol>
<li>成像  </li>
<li>寻找符合条件的发光物作为灯条的候选  </li>
<li>两两组合灯条候选，判断其是否构成一个装甲片</li>
<li>保存符合条件的装甲片</li>
<li>从保存的装甲片中按照一定的规则选取需要打击的单个装甲片</li>
</ol>
<p>成像是整个系统中非常重要的一步，比赛场地会存在比较大的环境干扰因素，但因装甲片有明显的发光标志物，所以我们采用了高帧率，低曝光率的工业相机作为成像设备，通过设定低曝光时间，能过滤掉场地中大部分的干扰物，同时能对发光物体有较好的成像效果。  </p>
<p>寻找灯条候选首先会对图像进行二值化，然后寻找轮廓，并按照规则依次判断每个轮廓是否是装甲片。  </p>
<p>两两组合灯条候选，判断其是否构成一个装甲片也是通过一系列的规则进行判断。  </p>
<p>通常处于画面中心的目标是最理想的打击目标，所以我们会优先选择离中心最近的打击目标，可以通过重载类的小于操作符，实现类按照离中心距离实现升序排序。  </p>
<ul>
<li>估算装甲片距离  </li>
</ul>
<p>在实际测试过程中，会发现弹丸射击存在弹道现象，也就是会出现弹道抛物线，造成了就算找到装甲片也可能打不中的情况，最直接的方法就是测量出需要打击的装甲片离相机的距离（相机位于枪管上方），进而根据目标距离调整枪口的角度以及发射弹丸的速度，实现更加精准的打击。  </p>
<p>上述问题属于单目测算深度问题，可以通过像素坐标和世界坐标的转换实现<br><img src="/interview/2021/03/07/RoboMaster/%E7%9B%B8%E6%9C%BA%E5%9D%90%E6%A0%872%E4%B8%96%E7%95%8C%E5%9D%90%E6%A0%87.jpg" alt="相机坐标2世界坐标"><br>(u, v)是像素坐标，Xw, Yw, Zw是世界坐标，Zc是相机坐标的深度。  </p>
<p>从上述公式可得，我们只需要知道相机内外参，以及世界坐标的坐标点，和其在像素坐标中的对应点，就可以计算出世界坐标的坐标点所对应的相机坐标的深度。  </p>
<p>相机内参可以通过相机的畸变矫正获得，我们可以把需要打击的装甲片中心点设置为世界坐标原点，即（0，0，0），所以我们需要求解的只有相机外参。  </p>
<p>相机外参可以通过求解PNP问题得出，因为我们可以得到装甲片的四个顶点，在设定装甲片中心为世界坐标原点的前提下，是可以知道这四个装甲片顶点的世界坐标的，我们也能找到这四个顶点的像素坐标，所以能够求解这一PNP问题。  </p>
<ul>
<li>调整射击角度和速度  </li>
</ul>
<p>这一过程通过PC和下位机的串口通信实现，PC根据计算出来的信息，发送相应的信号给下位机。  </p>
<h3 id="实现环境和结果"><a href="#实现环境和结果" class="headerlink" title="实现环境和结果"></a>实现环境和结果</h3><ul>
<li><p>实现环境<br>Ubuntu 16.04<br>OpenCV 3.4+<br>C++  </p>
</li>
<li><p>实现效果<br>FPS ：40<br>单目测距精度：三米内误差在10厘米内<br>命中率：运动情况下40%左右</p>
</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="mailto:undefined">Luo Jiehao</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="https://luo_13.gitee.io/interview/2021/03/07/RoboMaster/">https://luo_13.gitee.io/interview/2021/03/07/RoboMaster/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/interview/2021/03/07/CVTE%E5%AE%9E%E4%B9%A0/"><img class="prev-cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="onerror=null;src='/interview/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">CVTE实习</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="/interview/null" onerror="this.onerror=null;this.src='/interview/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Luo Jiehao</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/interview/archives/"><div class="headline">Articles</div><div class="length-num">4</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%83%8C%E6%99%AF%E4%BB%8B%E7%BB%8D"><span class="toc-number">1.</span> <span class="toc-text">背景介绍</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%BB%E8%A6%81%E8%B4%A1%E7%8C%AE"><span class="toc-number">2.</span> <span class="toc-text">主要贡献</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%8A%A8%E5%B0%84%E5%87%BB%E6%A8%A1%E5%9D%97%E5%8A%9F%E8%83%BD"><span class="toc-number">3.</span> <span class="toc-text">自动射击模块功能</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8A%9F%E8%83%BD%E5%AE%9E%E7%8E%B0"><span class="toc-number">4.</span> <span class="toc-text">功能实现</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0%E7%8E%AF%E5%A2%83%E5%92%8C%E7%BB%93%E6%9E%9C"><span class="toc-number">5.</span> <span class="toc-text">实现环境和结果</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/interview/2021/03/07/%E7%99%BD%E4%BA%91%E6%9C%BA%E5%9C%BA%E9%81%93%E8%B7%AF%E6%83%85%E5%86%B5%E7%9B%91%E6%8E%A7/" title="白云机场道路情况监控"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/interview/img/404.jpg'" alt="白云机场道路情况监控"/></a><div class="content"><a class="title" href="/interview/2021/03/07/%E7%99%BD%E4%BA%91%E6%9C%BA%E5%9C%BA%E9%81%93%E8%B7%AF%E6%83%85%E5%86%B5%E7%9B%91%E6%8E%A7/" title="白云机场道路情况监控">白云机场道路情况监控</a><time datetime="2021-03-07T12:48:43.000Z" title="Created 2021-03-07 20:48:43">2021-03-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/interview/2021/03/07/%E6%B3%B0%E7%A7%91%E7%94%B5%E5%AD%90AICUP%E6%AF%94%E8%B5%9B/" title="泰科电子AI CUP比赛"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/interview/img/404.jpg'" alt="泰科电子AI CUP比赛"/></a><div class="content"><a class="title" href="/interview/2021/03/07/%E6%B3%B0%E7%A7%91%E7%94%B5%E5%AD%90AICUP%E6%AF%94%E8%B5%9B/" title="泰科电子AI CUP比赛">泰科电子AI CUP比赛</a><time datetime="2021-03-07T12:48:42.000Z" title="Created 2021-03-07 20:48:42">2021-03-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/interview/2021/03/07/CVTE%E5%AE%9E%E4%B9%A0/" title="CVTE实习"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/interview/img/404.jpg'" alt="CVTE实习"/></a><div class="content"><a class="title" href="/interview/2021/03/07/CVTE%E5%AE%9E%E4%B9%A0/" title="CVTE实习">CVTE实习</a><time datetime="2021-03-07T12:48:41.000Z" title="Created 2021-03-07 20:48:41">2021-03-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/interview/2021/03/07/RoboMaster/" title="Robomaster"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/interview/img/404.jpg'" alt="Robomaster"/></a><div class="content"><a class="title" href="/interview/2021/03/07/RoboMaster/" title="Robomaster">Robomaster</a><time datetime="2021-03-07T12:48:40.000Z" title="Created 2021-03-07 20:48:40">2021-03-07</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By Luo Jiehao</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/interview/js/utils.js"></script><script src="/interview/js/main.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>